package com.ruoyi.iot.service.impl;

import java.util.List;

import com.ruoyi.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.iot.mapper.IotServiceConfigMapper;
import com.ruoyi.iot.domain.IotServiceConfig;
import com.ruoyi.iot.service.IIotServiceConfigService;

/**
 * 第三方服务配置Service业务层处理
 *
 * @author rww
 * @date 2023-09-22
 */
@Service
public class IotServiceConfigServiceImpl implements IIotServiceConfigService
{
    public static final String cache_key = "tscs_key_";

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IotServiceConfigMapper iotServiceConfigMapper;

    /**
     * 查询第三方服务配置
     *
     * @param id 第三方服务配置主键
     * @return 第三方服务配置
     */
    @Override
    public IotServiceConfig selectIotServiceConfigById(String id)
    {
        return iotServiceConfigMapper.selectIotServiceConfigById(id);
    }

    /**
     * 查询第三方服务配置列表
     *
     * @param iotServiceConfig 第三方服务配置
     * @return 第三方服务配置
     */
    @Override
    public List<IotServiceConfig> selectIotServiceConfigList(IotServiceConfig iotServiceConfig)
    {
        return iotServiceConfigMapper.selectIotServiceConfigList(iotServiceConfig);
    }

    /**
     * 新增第三方服务配置
     *
     * @param iotServiceConfig 第三方服务配置
     * @return 结果
     */
    @Override
    public int insertIotServiceConfig(IotServiceConfig iotServiceConfig)
    {
        return iotServiceConfigMapper.insertIotServiceConfig(iotServiceConfig);
    }

    /**
     * 修改第三方服务配置
     *
     * @param iotServiceConfig 第三方服务配置
     * @return 结果
     */
    @Override
    public int updateIotServiceConfig(IotServiceConfig iotServiceConfig)
    {
        return iotServiceConfigMapper.updateIotServiceConfig(iotServiceConfig);
    }

    /**
     * 批量删除第三方服务配置
     *
     * @param ids 需要删除的第三方服务配置主键
     * @return 结果
     */
    @Override
    public int deleteIotServiceConfigByIds(String[] ids)
    {
        return iotServiceConfigMapper.deleteIotServiceConfigByIds(ids);
    }

    /**
     * 删除第三方服务配置信息
     *
     * @param id 第三方服务配置主键
     * @return 结果
     */
    @Override
    public int deleteIotServiceConfigById(String id)
    {
        return iotServiceConfigMapper.deleteIotServiceConfigById(id);
    }

    @Override
    public IotServiceConfig getByKey(String keyType) {
        IotServiceConfig entity = redisCache.getCacheObject(cache_key+keyType);
        if(entity==null){
            entity = iotServiceConfigMapper.selectIotServiceConfigByKey(keyType);
            if(entity!=null){
                redisCache.setCacheObject(cache_key+keyType,entity);
            }else {
                return null;
            }
        }
        return entity;
    }
}
